package com.itheima.d1_junit;

import org.junit.*;

import static org.junit.Assert.*;

public class CalculatorTest {
    Calculator calculator;

    @Before
    public void beforeTest() {
        System.out.println("before方法执行");
        calculator = new Calculator();
    }

    @After
    public void afterTest() {
        //释放资源
        System.out.println("after方法执行");
        calculator = null;
    }

    @BeforeClass
    public static void beforeClassTest() {
        System.out.println("beforeClass方法执行");
    }

    @AfterClass
    public static void afterClassTest() {
        System.out.println("afterClass方法执行");
    }

    @Test
    public void divide() {
        int divide = calculator.divide(10, 5);
        Assert.assertEquals(2,divide);

        System.out.println("test方法运行");
    }

    @Test
    public void add() {
//        Calculator calculator = new Calculator();
        int add = calculator.add(10, 20);
        System.out.println("add = " + add);
        //实际的结果就是add变量保存的值，方法运行后实际得到的结果
        Assert.assertEquals(30,add);
        Assert.assertEquals("加法功能错了～",30,add);
    }

    @Test
    public void subtract() {
    }

    @Test
    public void multiply() {
//        Calculator calculator = new Calculator();
        //测试用例
        int multiply = calculator.multiply(2,2);
//        System.out.println("multiply = " + multiply);
        Assert.assertEquals(4,multiply);
        //尽可能多的测试用例
        Assert.assertEquals(6,calculator.multiply(2,3));
    }

    @Test
    public void testDivide() {
    }
}